package com.renchunlin.logindemo01.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.renchunlin.logindemo01.domain.QequestUserData
import com.renchunlin.logindemo01.domain.ResponseLogin
import com.renchunlin.logindemo01.repository.OnRepository
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/6/23.
 * PS: Not easy to write code, please indicate.
 */
class OnViewMode : ViewModel() {

    val loginResult = MutableLiveData<ResponseLogin>()

    private val onRepository by lazy {
        OnRepository()
    }

    /**
     * 去登录
     */
    fun toLogin(vCode: String, user: QequestUserData) {
        val responseLogin = onRepository.getOnLogin(vCode, user)
        responseLogin.enqueue(object : Callback<ResponseLogin> {
            override fun onResponse(call: Call<ResponseLogin>, response: Response<ResponseLogin>) {
                val code = response.code()
                val body = response.body()
                val code1 = body?.code
                Log.i("chen", "onResponse: $code1")
            }

            override fun onFailure(call: Call<ResponseLogin>, t: Throwable) {
                Log.i("chen", "onFailure: ${t.message}")
            }

        })
    }
}